
function Bcr4bp_ScnEMRot(tau , aux)
%
% 画BCR4BP场景，EMRot旋转系
%
% 时间：2024年06月03日
% 作者：张晨
% 单位：CSU
% 邮箱：chenzhang@csu.ac.cn
%%%%%%%%%%%%%%%%%%%%%%%

% ---------------- 载入参数 ----------------
mu = aux.EMRot.mu;
mus = aux.EMRot.mus;
as = aux.EMRot.as;
ws = aux.EMRot.ws;

% 计算地月连线相对SB1rot夹角
thetas = ws * tau;

% B1位置
xb1 = 0;
yb1 = 0;

% B2位置
xb2 = as * mus / (mus + 1) * cos(thetas);
yb2 = as * mus / (mus + 1) * sin(thetas);

% 地球位置
xe = - mu;
ye = 0;

% 月球位置
xm = 1 - mu;
ym = 0;

% 太阳位置
xs = as * cos(thetas);
ys = as * sin(thetas);

text(xs , ys , 'Sun' , 'linewidth' , 1);
text(xe , ye , 'Earth' , 'linewidth' , 1);
text(xm , ym , 'Moon' , 'linewidth' , 1);
% text(xb1 , yb1 , 'B1' , 'linewidth' , 1);
% text(xb2 , yb2 , 'B2' , 'linewidth' , 1);

% ----------------------- fig1 --------------------------------------
figure1;

% 画日地月
sunReq = 696340 / aux.dim.EMRot_l;
earthReq = 6378 / aux.dim.EMRot_l;
moonReq = 1738 / aux.dim.EMRot_l;

radius = sunReq;
center = [xs, ys]; % 圆心位置
theta = linspace(0, 2*pi, 100); % 构造圆的角度序列
x = center(1) + radius * cos(theta); % x坐标
y = center(2) + radius * sin(theta); % y坐标
fill(x, y, [0.9290 , 0.6940 , 0.1250]);

radius = earthReq;
center = [xe, ye]; % 圆心位置
theta = linspace(0, 2*pi, 100); % 构造圆的角度序列
x = center(1) + radius * cos(theta); % x坐标
y = center(2) + radius * sin(theta); % y坐标
fill(x, y, [0 , 0.4470 , 0.7410]);

radius = moonReq;
center = [xm, ym]; % 圆心位置
theta = linspace(0, 2*pi, 100); % 构造圆的角度序列
x = center(1) + radius * cos(theta); % x坐标
y = center(2) + radius * sin(theta); % y坐标
fill(x, y, [0.5 , 0.5 , 0.5]);

% 画LEO和LLO
leoRmag = aux.dim.rMagLEO / aux.dim.EMRot_l;
plot_o([xe , ye] , leoRmag , 'k--' , 0.5);

lloRmag = aux.dim.rMagLLO / aux.dim.EMRot_l;
plot_o([xm , ym] , lloRmag , 'k--' , 0.5);

% 画B1和B2
plot(xb1 , yb1 , 'r.' , 'markersize' , 5 , 'linewidth' , 1);
plot(xb2 , yb2 , 'r.' , 'markersize' , 5 , 'linewidth' , 1);

% 画Sun绕B2轨道
rMag_b2s = as;
plot_o([0 , 0] , rMag_b2s , 'k--' , 1);

% 画平动点
[Li_pos , ~] = Cr3bp_Li(mu);
plot(Li_pos(1,1) , Li_pos(1,2) , 'r+' , 'linewidth' , 1.2);
plot(Li_pos(2,1) , Li_pos(2,2) , 'r+' , 'linewidth' , 1.2);
plot(Li_pos(3,1) , Li_pos(3,2) , 'r+' , 'linewidth' , 1.2);
plot(Li_pos(4,1) , Li_pos(4,2) , 'r+' , 'linewidth' , 1.2);
plot(Li_pos(5,1) , Li_pos(5,2) , 'r+' , 'linewidth' , 1.2);

text(Li_pos(1,1) , Li_pos(1,2) - 0.001, 'L1' , 'linewidth' , 1.2);
text(Li_pos(2,1) , Li_pos(2,2) - 0.001, 'L2' , 'linewidth' , 1.2);
text(Li_pos(3,1) , Li_pos(3,2) - 0.001, 'L3' , 'linewidth' , 1.2);
text(Li_pos(4,1) , Li_pos(4,2) - 0.001, 'L4' , 'linewidth' , 1.2);
text(Li_pos(5,1) , Li_pos(5,2) - 0.001, 'L5' , 'linewidth' , 1.2);

xlabel('x / LU');
ylabel('y / LU');
view(0 , 90);
title('Earth-Moon Rotating')

axisBd = 200e4 / aux.dim.EMRot_l;
axis([xb1 - axisBd , xb1 + axisBd , -axisBd , axisBd]);

end
